﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RoboRace_Shared
{
    //Public event delegate declarations.
    public delegate void OnPlayerJoin(string name);
    public delegate void OnGameStarted(string message);
    public delegate void OnGameStopped(string message);

    [Serializable]
    public class Game
    {
        public event OnPlayerJoin PlayerJoin;
        public event OnGameStarted GameStarted;
        public event OnGameStopped GameStopped;

        private int _playerCount;
        private Board _gameBoard;
        private List<Player> _players;
        private Boolean _isStarted;
        private List<Robot> _robots;

        public int PlayerCount { get { return _playerCount; } }
        public Boolean IsRunning { get { return _isStarted; } }

        public Game()
        {
            this._playerCount = 5;
            this._gameBoard = new Board(5, 5);
            this._players = new List<Player>();
            this._isStarted = false;
            this._robots = new List<Robot>();
        }

        public void Join(string name)
        {
            Player player = new Player(name);
            this._players.Add(player);
            this._robots.Add(new Robot(name, player.Guid));

            PlayerJoin(this._players.Count.ToString());
            if (this._players.Count == _playerCount)
            {
                Start();
            }
        }

        private void Start()
        {
           this._isStarted = true;
            GameStarted("Game has started!");
        }

        private void Stop()
        {
            this._isStarted = false;
            GameStopped("Game has ended.");
        }
    }
}
